<?php

$page = "Profile";

include_once("common.php");


// If the user is logged in, we want to send them to the page where
// they can actually use the application.
if(!gpp_is_authenticated())
{
	gpp_redirect("entrance");
}

if(isset($_POST['submitted']))
{
	$message = gpp_update_account();
}

gpp_print_header($page, "");

function print_if_pursuing($major)
{
	if(strtolower($_SESSION['pursuing']) == strtolower($major))
		echo ' selected="selected"';
}

// Since we have printed the header, we are already in the <body> statement with a greeting
// above.

?>

<p>To edit your account info, use the fields below. If you want to change your e-mail address,
contact chris.cahoon@gmail.com.</p><p> To change your password, enter the new password in each of these password fields. Otherwise, leave them blank.</p>

<h2><?php echo $message ?></h2>

<p>User: <?php echo $_SESSION['email'] ?></p>

<div id="profile_form">
	<form method="POST" name="login" action="profile.php">
	<input type="hidden" name="submitted" value="true" />
	<table>
    <tr>
        <td><label for="name_first">First name:</label></td>
        <td><input type="text" name="name_first" id="name_first" value="<?php echo $_SESSION['name_first'] ?>" /></td>
    </tr>
    <tr>
        <td><label for="name_last">Last name:</label></td>
        <td><input type="text" name="name_last" id="name_last" value="<?php echo $_SESSION['name_last'] ?>" /></td>
    </tr>
    <tr>
        <td><label for="major">Major:</label></td>
        <td>
        <select name="pursuing" id="pursuing">
            <option value="CMSC"<?php print_if_pursuing("CMSC") ?>>Computer Science (CMSC)</option>
            <option value="IS"<?php print_if_pursuing("IS") ?>>Information Systems (IS)</option>
            <option value="CMSCIS"<?php print_if_pursuing("CMSCIS") ?>>CMSC and IS Double Major (CMSC & IS)</option>
            <option value="ISCMSCminor"<?php print_if_pursuing("ISCMSCminor") ?>>IS Major and CMSC Minor</option>
	    </select>
        </td>
    </tr>
    <tr>
        <td><label for="semesters_left">Semesters<br />remaining:</label></td>
        <td><input type="text" name="semesters_left" id="semesters_left" value="<?php echo $_SESSION['semesters_left'] ?>" /></td>
    </tr>
    <tr>
        <td><label for="password">Password:</label></td>
        <td><input type="password" name="password" id="password"></td>
    </tr>
    <tr>
        <td><label for="password2">Password Again:</label></td>
        <td><input type="password" name="password2" id="password2"></td>
    </tr>
    <tr>
        <td colspan="2"><input type="submit" name="update" value="Update" /></td>
    </tr>
    </table>
    
	</form>
</div>


<?php 

gpp_print_footer();

?>